<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>材料签收</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../resources/css/style.css" media="all">
		<style>
			.layui-input-inline {
				width: 80%;
			}
			/*.layui-form-item .layui-input-inline{width: 165px;}*/
			
			.masksx .forms {
				padding-left: 0;
				text-align: center;
			}
			
			.masksx {
				width: 700px;
				height: 80%!important;
			}
			
			.mask input {
				width: 100%!important;
			}
			
			.mask .layui-select-title {
				width: 550px;
			}
			
			.layui-inline {
				margin-bottom: 10px;
			}
			
			.layui-upload {
				text-align: left;
			}
			
			#demo2 img {
				width: 120px;
				height: 120px;
			}
			
			.imgs {
				position: relative;
				width: 120px;
				height: 120px;
				float: left;
			}
			
			._ingshan {
				position: absolute;
				right: 0px;
				top: 0px;
				border: 1px solid #E3e3e3;
				border-radius: 50%;
				width: 20px;
				height: 20px;
				text-align: center;
			}
			.recvName{margin-bottom: 10px;}
			@media only screen and (min-width: 321px) and (max-width: 1024px) {
				.layui-form-pane .layui-input-inline {
					width: 80%;
				}
				._inkong {
					width: auto!important;
				}
				.layui-form-item .layui-input-inline {
					width: 100%;
				}
				.masksx {
					height: 80%;
				}

			}

			.layui-form-label {
				padding-left: 0;
				height: 20px;
			}
			.material-mask-top li{
				text-align: left;
				padding: 10px;
				list-style: none;
			}
		
			.mask .num{
				width: 30px !important;
			}
			.rm_Code,.eppName,.compName1,.compName,.r_adr{
				padding-left: 20px;
			}
			.layui-input-block{
				margin-left: 0;
			}
			.recvNameL,.recvNameR{display: inline-block;}
			.recvNameL{text-align: left;width: 30%;}
			.recvNameR{width: 70%;}
			.layui-form-item .layui-input-inline{width: 80%;}
		</style>
	</head>

	<body>
	<div class="_PC">
		<a class="dayin" type="button" id="dlink"   style="float: right; position: fixed; right: 50px; bottom: 50px; z-index: 999;"></a>
		<form class="layui-form layui-form-pane" action="">
			<div class="formTop" style="font-size:12px;">
				<div class="layui-form-item layui-col-xs3 layui-col-sm3 layui-col-md3">
					<div class="layui-input-inline">
						<input type="text" name="username" lay-verify="required" placeholder="项目名称" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-inline layui-col-xs3 layui-col-sm3 layui-col-md3">
					<div class="layui-input-inline">
						<input type="text" class="layui-input" id="test-limit3" placeholder="请选择签收开始日期">
						<div class="icons">

						</div>
					</div>
				</div>
				<div class="layui-inline layui-col-xs3 layui-col-sm3 layui-col-md3">

					<div class="layui-input-inline">
						<input type="text" class="layui-input" id="test-limit4" placeholder="请选择签收结束日期">
						<div class="icons">

						</div>
					</div>
				</div>

				<div class="layui-col-xs3 layui-col-sm3 layui-col-md3">
					<button class="layui-btn" type="button" onclick="query()">查询</button>
					<button class="layui-btn" type="button" onclick="checkTab()" style="margin-bottom: 10px;">核验表
					</button>
				</div>

			</div>

			<table id="demo" lay-filter="test"></table>

			<script type="text/html" id="barDemo">
				<a class="layui-btn layui-btn-sm layui-btn-danger bianji quanxian" lay-event="bianji" QX="api/ctteam/matSign.do">签收</a>
				<a class="layui-btn layui-btn-sm chakan quanxian" lay-event="detail" QX="api/ctteam/matSignDetails.do">详情</a>
				<a class="layui-btn layui-btn-sm chakan quanxian" lay-event="print" QX="api/ctteam/matSignDetails.do">打印</a>
			</script>
		</form>
		<div class="mask">
			<div class="masksx">
				<div class="title"><span class="titleL">签收</span><span class="close">×</span></div>
				<div class="forms">
					<form class="layui-form addUser" method="post" action="">

						<div class="layui-inline">
							<ul class="material-mask-top">
								<li><span>供料单号:</span><span class="rm_Code"></span></li>
								<li><span>工程名称:</span><span class="eppName"></span></li>
								<li><span>施工单位:</span><span class="compName1"></span></li>
								<li><span>供货单位:</span><span class="compName"></span></li>
								<li><span>收货地址:</span><span class="r_adr"></span></li>

							</ul>


							<div class="layui-input-inline _inkong" style="width: 650px;">
								<table class="layui-table">
									<thead>
									<tr>
										<th>材料名称</th>
										<th>材料规格</th>
										<th>计量单位</th>
										<th>送料数</th>
										<th>签收数量</th>
									</tr>
									</thead>
									<tbody class="shenqing">
									<!--<tr>-->
									<!--<td class="check">-->
									<!--<div class="layui-form-item" pane="">-->
									<!--<div class="layui-input-block">-->
									<!--<input type="checkbox" name="like1[write]" lay-filter="filter" lay-skin="primary" title=''>-->
									<!--</div>-->
									<!--</div>-->
									<!--</td>-->
									<!--<td class="p-name">水泥</td>-->
									<!--<td class="p-rule">PC32.5</td>-->
									<!--<td class="p-unit">t</td>-->
									<!--<td class="p-num">20</td>-->
									<!--<td>-->
									<!--<input type="number" name="username" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">-->
									<!--</td>-->
									<!--</tr>-->

									</tbody>
								</table>
								<div class="recvName">
									<p><span class="recvNameL">收料单位及经手人:</span><span class="recvNameR"><input type="text" name="recvName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input"></span></p>
								</div>
								<div class="recvName_Opinion">
									<p><span class="recvNameL">收料单位及经手人意见:</span><span class="recvNameR"><input type="text" name="recvName_Opinion" placeholder="请输入" lay-verify="required" autocomplete="off" class="layui-input"></span></p>
								</div>
							</div>
						</div>

						<div class="_submit" style="text-align: center";>
							<button class="layui-btn layui-btn-sm tijiao" lay-submit lay-filter="_subm" style="margin-right: 25px;">提交</button>
							<button class="layui-btn layui-btn-sm tijiao layui-btn-danger" lay-submit lay-filter="_jujue" style="margin-right: 25px;">拒绝签收</button>
						</div>

					</form>

				</div>
			</div>

		</div>
	</div>


	<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
		<script src="../../../resources/js/style.js"></script>
		<script src="../../../resources/js/api.js"></script>
		<script type="text/javascript">
            function checkTab() {
                layui.use(['form', 'layedit', 'laydate','table','element'], function() {
                    var compid =  getCookie('yanzheng').split("|")[1];
                    layer.open({
                        type: 2,
                        title: '核验单',
                        maxmin: 'true',
                        shadeClose: true,
                        area: ['520px', '340px'], //宽高
                        shade: 0.8,
                        content: urls + '/ureport/preview?_u=file:build.check.ureport.xml&buildCode='+ compid //iframe的url
                    });
                });
            }
			function query() {
				layui.use(['form', 'layedit', 'laydate', 'table', 'element'], function() {
					var form = layui.form,
						table = layui.table;
					var pronName = $("[name='username']").val();
					var begintime = $('#test-limit3').val();
					var endtime = $('#test-limit4').val();

					if(!AntiSqlValid(pronName)) {
					    if(lbq('api/ctteam/matSignList.do')){
                            API.material({
                                'p':getCookie('yanzheng'),
                                'proName': pronName,
                                'begintime': begintime,
                                'endtime': endtime

                            })
						}

					} else {
						layer.msg('请勿输入特殊符号或敏感文字');
					};
				})

			}
			layui.use(['form', 'layedit', 'laydate', 'table','flow'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					table = layui.table,
                    flow=layui.flow,
					laydate = layui.laydate;
                dayintishi('.dayin');
                jiazais();

				var ts=getCookie('yanzheng');
				ts=ts.split('|');
				$('[name="recvName"]').val(ts[0]);
                //前后若干天可选，这里设置不能选过去的日期      最远可选1000天之后
				panduanshijiantow('#test-limit3', '#test-limit4', 1000, 1000, '.layui-btn-normal'); //查询 开始结束时间判断
                if(lbq('api/ctteam/matSignList.do')) {

                    API.material({'p': getCookie('yanzheng')});
                }
				$('.close').click(function() { //遮罩层隐藏
					$('.mask').hide();
				})

                $(document).on('blur','[type="number"]',function () {
                    if($(this).val()<0){
                        layer.msg('数量不能小于0');
                        $(this).val(0);
                    }
                })
				laydate.render({
					elem: '#date'
				});
				var ccuid = '';
                //监听全选
                form.on('checkbox(allChoose)', function(data){
                    var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');         //找到tbody下的所有多选框
                    child.each(function(index, item){                             //循环每个参数item  每个多选框
                        item.checked = data.elem.checked;                         //所有多选框  选中或取消选中
//                $(item).trigger('click');
                    });
                    form.render('checkbox');                                      //局部刷新多选框  保持页面操作一致性
                });
                //监听单个点击多选
                form.on('checkbox(filter)', function(data){
                    var _this=data.othis;
                    var chuandi=new Object();
                    chuandi.jia=$(_this).parents('tr').attr('idang');
                    chuandi.id=$(_this).parents('tr').attr('id');
                    chuandi.mat_id=$(_this).parents('tr').attr('mat_id');
                    chuandi.names=_this.parents('th').next().text();
                    chuandi.guige=_this.parents('th').next().next().text();
                    chuandi.num=_this.parents('th').next().next().next().text();
                  
                    $('.tijiao').removeClass('layui-btn-disabled');
                    if(data.elem.checked){          //如果多选框被选中  给下半部添加内容
                        $('.beixuan table tbody').append('<tr id="'+chuandi.id+'" mat_id="'+chuandi.mat_id+'" idang="'+chuandi.jia+'">\n' +
                            '                                    <th class="names">'+chuandi.names+'</th>\n' +
                            '                                    <th class="guige">'+chuandi.guige+'</th>\n' +
                            '                                    <th class="nums">\n' +
                            '                                        <input type="number" class="inputs" lay-verify="required" value="'+chuandi.num+'"/>\n' +
                            '                                        <input type="hidden" class="numson" lay-verify="required" value="'+chuandi.num+'"/>\n' +
                            '                                    </th>\n' +
                            '                                </tr>')
                    }else{                          //否则循环下半部所有的tr删除对应的tr
                        $('.beixuan table tbody tr').each(function () {
                            if($(this).attr('id')==chuandi.id){
                                $(this).remove();
                            }
                        })
                    }
                });
				var cID='';
				//监听工具条
				table.on('tool(test)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
					var data = obj.data; //获得当前行数据
					var layEvent = obj.event; //获得 lay-event 对应的值
					var tr = obj.tr; //获得当前行 tr 的DOM对象
					if(layEvent === 'detail') { //详情
						//console.log(obj)
						sessionStorage.ccuid = obj.data.rm_Code;
						var datas=new Object();					//新建对象 传递参数
						datas=JSON.stringify(obj);				//json对象转字符串
						sessionStorage.data_material=datas;		//传递当前列表信息给详情页调用
						window.location.href = 'materialdetails.html';
					} else if(layEvent === 'bianji') { //签收
						//console.log(obj);
						//console.log(obj.rm_Code)
						ajaxs('/api/ctteam/matSignDetails.do',"post",{'type':'c','rm_code':obj.data.rm_Code,'p':getCookie('yanzheng')},function (data) {
		//console.log(data)
							var datas=data.data;
							$('._inkong table tbody').html('');
							for(var i=0;i<datas.length;i++){
                                cID=datas[0].rm_Code;
							    $('._inkong table tbody').append('<tr id="'+datas[i].id+'">\n' +
                                    '     <td class="p-name">'+datas[i].mat_Name+'</td>\n' +
                                    '     <td class="p-rule">'+datas[i].mat_Spec+'</td>\n' +
                                    '     <td class="p-unit">'+datas[i].mat_Bit+'</td>\n' +
                                    '   <td class="p-num">'+datas[i].send_Num+'</td>\n' +
                                    '     <td class="p-nums">  <input type="number" name="username" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="'+datas[i].send_Num+'"></td>\n' +
                                    ' </tr>')
							}
                            $('.recvName .recvNameR').text(datas[0].recvName)
                            $('.recvName_Opinion .recvNameR').text(datas[0].recvName_Opinion)
							form.render();
                        })
						$('.mask').show();
						$('.titleL').html('签收');
						$(".p-name").html(obj.data.supName);
						$(".rm_Code").html(obj.data.rm_Code);
						$(".compName1").html(obj.data.compName1);
						$(".eppName").html(obj.data.proName);
						$('.compName').html(obj.data.compName);
						$('.r_adr').html(obj.data.r_adr);
					} else if ( layEvent === 'print' ){
                        layer.open({
                            type: 2,
                            title: '核验单',
                            maxmin: 'true',
                            shadeClose: true,
                            area: ['520px', '340px'], //宽高
                            shade: 0.8,
                            content: urls + '/ureport/preview?_u=file:recv_ticket.ureport.xml&rmCode=' + obj.data.rm_Code  //iframe的url
                        });
					}
				});
				form.on('submit(_subm)', function(data) {
					//console.log(data)
					var canshu='';
					$('.shenqing tr').each(function () {
						var xuanzhong=$(this).children('.check').children().children().children('.checks');		//获取复选框
						//如果复选框被选中就执行
						canshu+=$(this).attr('id')+','+$(this).children('.p-nums').children('input').val()+'|';
                    })
                    canshu=canshu.substring(0,canshu.length-1);
                    //console.log(canshu)
                    data.field.rm_code=$('.rm_Code').text();
                    data.field.recvName=$('[name="recvName"]').val();
                    data.field.recvName_Opinion=$('[name="recvName_Opinion"]').val();
                    data.field.sd=canshu;
                    data.field.p=getCookie('yanzheng');
					console.log( data.field,'>>>>>>>>>>>>>>>>>>')
					formAlertAjax('/api/ctteam/matSign.do', data.field, '.tijiao');
					return false;
				});
                form.on('submit(_jujue)', function(data) {
                    //console.log(data)
					data.field.rm_code=cID;
                    data.field.recvName_Opinion=$('[name="recvName_Opinion"]').val();
                    data.field.p=getCookie('yanzheng');
                    formAlertAjax('/api/ctteam/matNoSign.do', data.field, '.tijiao');
                    return false;
                })


			})
		</script>

	</body>

</html>